﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProxyPattern.DemoThree
{
    public class GamePlayer : IGamePlayer
    {
        private string name = string.Empty;
        private IGamePlayer proxy = null;

        /// <summary>
        /// 構造函數
        /// </summary>
        /// <param name="_name"></param>
        public GamePlayer(string _name)
        {
            this.name = _name;

        }

        /// <summary>
        /// 找到自己的代理
        /// </summary>
        /// <returns></returns>
        public IGamePlayer getProxy()
        {
            this.proxy = new GamePlayerProxy(this);
            return this.proxy;
        }

        public string killBoss()
        {
            if (this.isProxy())
            {
                return this.name + " 在打怪!" + Environment.NewLine;
            }
            else
            {
                return "請使用指定的代理訪問 " + Environment.NewLine;
            }
        }

        public string login(string user, string password)
        {
            if (this.isProxy())
            {
                return "登錄名為：" + user + " 的用戶 " + this.name + " 登錄成功!" + Environment.NewLine;
            }
            else
            {
                return "請使用指定的代理訪問 " + Environment.NewLine;
            }
        }

        public string upgrade()
        {
            if (this.isProxy())
            {
                return this.name + " 又升了一級!" + Environment.NewLine;
            }
            else
            {
                return "請使用指定的代理訪問 " + Environment.NewLine;
            }
        }

        private bool isProxy()
        {
            if (this.proxy == null)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }

}
